package com.qk.controller;

import com.qk.common.Result;
import com.qk.entity.Activity;
import com.qk.service.ActivityService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/activities")
public class ActivityController {
    @Autowired
    private ActivityService activityService;

//    添加活动
    @PostMapping
    public Result add(@RequestBody Activity activity){
        log.info("新增活动:{}",activity);
        activityService.add(activity);
        return Result.success();
    }

//活动列表查询
    @GetMapping
     public Result list(Integer channel, Integer  type,Integer status,
                       @RequestParam(defaultValue = "1") Integer page,
                       @RequestParam(defaultValue = "10") Integer pageSize) {
//        调用Service分页查询
        log.info("查询活动列表:{},{},{},{},{}",channel, type,status,page,pageSize);
        return Result.success(activityService.list(channel,type,status,page,pageSize));
    }
//  根据ID查询
@GetMapping("/{id}")
public Result getById(@PathVariable Integer id){
//     System.out.println("查询id:"+id);
        log.info("查询id:{}",id);
        Activity activity = activityService.getById(id);
        return Result.success(activity);
    }
//    修改活动
    @PutMapping
    public Result update(@RequestBody Activity activity){
        log.info("修改活动:{}",activity);
        activityService.update(activity);
        return Result.success();
    }

//    删除 活动信息
    @DeleteMapping("/{id}")
    public Result deleteById(@PathVariable Integer id){
        log.info("删除id:{}",id);
        activityService.deleteById(id);
        return Result.success();
    }

//    查询指定类型的活动
    @GetMapping("/type/{type}")
    public Result select( @PathVariable Integer type){
        log.info("查询指定类型的活动:{}",type);
//        调用Service查询
        List<Activity> activityList = activityService.selectByType(type);
        return Result.success(activityList);
    }
}
